package com.laomou.poker.player;

import java.util.List;

import com.java.rapid.Action;
import com.java.rapid.Condition3;
import com.java.rapid.list.raListGroup;
import com.laomou.poker.Poker;
import com.laomou.poker.PokerGroup;
import com.laomou.poker.PokerGroupType;

public abstract class AiPlayer extends AbsPlayer {
    /**
     * 计算角色手上的牌的出牌组合
     */
    protected final void getAllPokerGroup(final List<PokerGroup> listPg) {
        getAllPokerGroup(listPg, getPlayerPoker());
    }

    /**
     * 计算牌的出牌组合
     */
    protected final void getAllPokerGroup(final List<PokerGroup> listPg,
                                          final List<Poker> listP) {
        raListGroup.from(listP).all(new Condition3<Poker>() {

            @Override
            public boolean apply(List<Poker> list) {
                PokerGroup pg = new PokerGroup();
                pg.addPokers(list);
                return isRule(pg);
            }
        }).forEach(new Action<List<Poker>>() {

            @Override
            public void call(List<Poker> list) {
                PokerGroup pg = new PokerGroup();
                pg.addPokers(list);
                if (!list.contains(pg)) {
                    listPg.add(pg);
                }
            }
        });
    }

    /**
     * 根据牌型类型找牌组合
     *
     * @param type
     * @return
     */
    protected final void getPokerByPokerGroupType(
            final List<PokerGroup> listPg, final List<Poker> listP,
            final PokerGroupType type, int s, int e) {
        raListGroup.from1(listP).select(s, e).filter(new Condition3<Poker>() {

            @Override
            public boolean apply(List<Poker> list) {
                PokerGroup pg = new PokerGroup();
                pg.addPokers(list);
                return isRule(pg) && pg.type() == type;
            }
        }).forEach(new Action<List<Poker>>() {

            @Override
            public void call(List<Poker> output) {
                PokerGroup pg = new PokerGroup();
                pg.addPokers(output);
                listPg.add(pg);
            }
        });
    }

    protected final void getPokerByPokerGroupType(
            final List<PokerGroup> listPg, final List<Poker> listP,
            final PokerGroupType type, int s) {
        getPokerByPokerGroupType(listPg, listP, type, s, s);
    }
}
